######################
#  Replication code for 'Mediating the Electoral Connection', forthcoming in the JOP
#  John Henderson and John Brooks
#  12/7/2015    
######################    

# readme.txt

All code and data are available in this replication dataset to rerun the main and robustness results from "Mediating the Electoral Connection". Additional code and data are included to produce the Nominate and IRT ideal point outcome measures, the simulations for the expected effect of rain-induced vote shifts on roll call behavior, and the (un)imputed datasets used through the analysis. This file provides a short roadmap to navigate these data and code files. 


Files::

<prelimMain.R> and <prelimRobust.R> load data, and produce a number of important objects for use in the main or robustness code. Most importantly, these files use pre-assigned values to 'non.missings' and 'fes.type' to build the appropriate versions of the data required -- 'non.missings' tunes whether post-redistricting years are included or not, and 'fes.type' tunes whether incumbent or district x decade fixed effects are used. Stratification objects are also assignedhere: 'full' (full analysis), 'demx' (just Dems), 'repx' (just Reps), 'modr' (Competitive), 'extr' (Safe). Additional data transformations are included for the various robustness results in <prelimRobust.R>. Note, the analysis here often loops over 'fes.type' and 'non.missings', to produce 4 versions of each result.

<coeftest.cluster.R> produces cluster IV standard errors

<plot.pval.R> a file by Rocio Titiunik that presents balance statistics in a nice plot

<rain_codebook.xlsx> codebook containing variable descriptions 

Folders::

:: build Data
  - contains the main baseline data, 'rain_data', which is found in <RainData.Rdata>; this object contains many additional covariates beyond those used in the study; <imputeCovs.R> uses multiple imputation to produce 'covs_all', 'covs_some', and 'covs_none' from 'rain_data'; generally, 'covs_some' is the dataset used throughout the analysis, where controls are imputed, but rain and the outcomes variables are not imputed; these objects are all contained in <FinalRainData.Rdata>

:: main
  - contains .R files to produce Tables 1, 2 and 3 in the main manuscript; throughout *fe_sumcl (including FEs and cluster SEs) models are those that are interpreted; 'dose' is Democratic vote margin intervention, and 'rain_day' or 'rain_weekend' are the instruments

:: fstats
 - contains .R and .do files to produce cluster F-statistics and Sargan over-identification test p-values for the main IV results in Table 3; note <table3_iv_fstats.R> must be run first to produce .dta files that are then called by STATA in 'table3_iv_fstats_4_3.do' and 'table3_iv_fstats_4_2.do';

:: stratifications 
  - contains .R files to produce Tables I, II, III in the online appendix, that are referenced in the main paper; also contains code to show rain induces Democratic losses in both safe and competitive districts as per Footnote 13;

:: slider
  - contains .R files to produce the Figures 2, 3, and 4 in the main paper; note, the *-analysis.R files must be run before the *plots.R files;

:: simulations 
  - contains .R files to produce Figure 1 in the main draft, and Figure VI in the appendix; also contains files to produce IRT and Nominate ideal points under <simulations/simruns>; note these simulations take some time to complete;

:: robustness
  - contains .R files to produce many robustness checks found in the online appendix; 

:: descriptives
  - contains .R files to produce the descriptives Table VII, and Figures III and IV in the online appendix; 

:: balance
  - contains files to produce the balance Figure I in the appendix; note the *analysis.R files must be run before the *plots.R files;

:: bootstrap
  - contains files to produce the bootstrap simulations results assessing instrument strength in Figure II in the appendix; 

:: leaveout
  - contains the files to conduct the leave-one-year-out analysis; note these take a very long time to run, and so the data from these runs are included alongside the files; note, the *-analysis.R files must be run before the *plots.R files;

:: nominate and battleground
  - contain some data files particular to producing and using the Nominate outcomes, or the robustness stratifications on presidential battleground states;


# eof